package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.vo.SysLikeRecordResp;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysLikeRecord;
import com.ruoyi.system.service.ISysLikeRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 点赞记录Controller
 * 
 * @author ruoyi
 * @date 2025-05-02
 */
@RestController
@RequestMapping("/system/record")
public class SysLikeRecordController extends BaseController
{
    @Autowired
    private ISysLikeRecordService sysLikeRecordService;

    /**
     * 查询点赞记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:likeRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysLikeRecord sysLikeRecord)
    {
        startPage();
        List<SysLikeRecordResp> list = sysLikeRecordService.selectSysLikeRecordList(sysLikeRecord);
        return getDataTable(list);
    }

    /**
     * 导出点赞记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:likeRecord:export')")
    @Log(title = "点赞记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysLikeRecord sysLikeRecord)
    {
        List<SysLikeRecordResp> list = sysLikeRecordService.selectSysLikeRecordList(sysLikeRecord);
        ExcelUtil<SysLikeRecordResp> util = new ExcelUtil<SysLikeRecordResp>(SysLikeRecordResp.class);
        util.exportExcel(response, list, "点赞记录数据");
    }

    /**
     * 获取点赞记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:likeRecord:query')")
    @GetMapping(value = "/{userId}/{type}/{targetId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId,
                              @PathVariable("type") Integer type,
                              @PathVariable("targetId") Long targetId)
    {
        return success(sysLikeRecordService.selectSysLikeRecordByUserIdAndTargetIdAndType(userId, targetId, type));
    }

    /**
     * 新增点赞记录
     */
    @PreAuthorize("@ss.hasPermi('system:likeRecord:add')")
    @Log(title = "点赞记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysLikeRecord sysLikeRecord)
    {
        return toAjax(sysLikeRecordService.insertSysLikeRecord(sysLikeRecord));
    }

    /**
     * 修改点赞记录
     */
    @PreAuthorize("@ss.hasPermi('system:likeRecord:edit')")
    @Log(title = "点赞记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysLikeRecord sysLikeRecord)
    {
        return toAjax(sysLikeRecordService.updateSysLikeRecord(sysLikeRecord));
    }

    /**
     * 删除点赞记录
     */
    @PreAuthorize("@ss.hasPermi('system:likeRecord:remove')")
    @Log(title = "点赞记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(sysLikeRecordService.deleteSysLikeRecordByUserIds(userIds));
    }

    @PostMapping("/front/add")
    public AjaxResult frontAdd(@RequestBody SysLikeRecord sysLikeRecord)
    {
        return success(sysLikeRecordService.insertSysLikeRecord(sysLikeRecord));
    }
}
